package com.zjh.admin.app.service.impl;

import com.zjh.admin.app.mapper.VideoMapper;
import com.zjh.admin.app.model.CollectEntity;
import com.zjh.admin.app.model.CommentEntity;
import com.zjh.admin.app.model.VideoEntity;
import com.zjh.admin.app.service.VideoService;
import com.zjh.core.base.baseservice.impl.AbstractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author WYX
 * @Description TODO
 * @Date 2019/11/17 18:18
 */
@Service("videoService")
public class VideoServiceImpl extends AbstractService<VideoEntity, Long> implements VideoService {

    @Autowired
    private VideoMapper videoMapper;

    @Autowired
    public void setBaseMapper() {
        super.setBaseMapper(videoMapper);
    }

    @Override
    public int updateLike(Long id) {
        return videoMapper.updateLike(id);
    }

    @Override
    public int collectVideo(Map<String, Object> parameter) {
        return videoMapper.collectVideo(parameter);
    }

    @Override
    public int deleteCollect(Map<String, Object> parameter) {
        return videoMapper.deleteCollect(parameter);
    }

    @Override
    public List<VideoEntity> findListForCollect(int uId) {
        List<CollectEntity> ids = videoMapper.findCollectByUid(uId);
        List<VideoEntity> videoEntityList = new ArrayList<>();
        for (CollectEntity collectEntity : ids) {
            VideoEntity videoEntity = videoMapper.findById(collectEntity.getcVideoEntity().getId());
            if (videoEntity != null)
                videoEntityList.add(videoEntity);
        }
        return videoEntityList;
    }

    @Override
    public int deleteBatchCollectById(Map<String, Object> parameter) {
        return videoMapper.deleteBatchCollectById(parameter);
    }

    @Override
    public VideoEntity findById(Long aLong) {
        return videoMapper.findById(aLong);
    }
}
